home *** CD-ROM | disk | FTP | other *** search
- { drawbits.pas -- Draw and use bitmaps at runtime }
-
- program DrawBits;
-
- uses WinTypes, WinProcs, WObjects;
-
- const
-
- bmHeight = 256; { Height of bitmap }
- bmWidth = 256; { Width of bitmap }
-
- type
-
- DrawBitsApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PDrawBitsWindow = ^DrawBitsWindow;
- DrawBitsWindow = object(TWindow)
- TheBitmap: HBitmap;
- constructor Init(AParent: PWindowsObject; ATitle: PChar);
- destructor Done;
- virtual;
- procedure SetupWindow;
- virtual;
- procedure Paint(PaintDC: HDC; var PaintInfo: TPaintStruct);
- virtual;
- end;
-
- {- Create and draw into a bitmap }
- function MakeBitmap(HWindow: HWnd): HBitmap;
- var
- Dc, MemDC: HDC;
- OldBitmap, HBits: HBitmap;
- X1, Y1, X2, Y2: Integer;
- begin
- {- Create bitmap and fill it with white }
- Dc := GetDC(HWindow);
- MemDC := CreateCompatibleDC(Dc);
- HBits := CreateCompatibleBitmap(Dc, bmWidth, bmHeight);
- OldBitmap := SelectObject(MemDC, HBits);
- PatBlt(MemDC, 0, 0, bmWidth, bmHeight, whiteness);
-
- {- Draw outline }
- Rectangle(MemDC, 0, 0, bmWidth, bmHeight);
-
- {- Draw concentric circles }
- X1 := 0; Y1 := 0; X2 := bmWidth; Y2 := bmHeight;
- while (X2 >= X1) and (Y2 >= Y1) do
- begin
- Ellipse(MemDC, X1, Y1, X2, Y2);
- X1 := X1 + 10;
- X2 := X2 - 10;
- Y1 := Y1 + 10;
- Y2 := Y2 - 10
- end;
-
- {- Draw X through bitmap's center }
- MoveTo(MemDC, 0, 0);
- LineTo(MemDC, bmWidth, bmHeight);
- MoveTo(MemDC, 0, bmHeight);
- LineTo(MemDC, bmWidth, 0);
-
- {- Dispose of supporting objects and return bitmap handle }
- SelectObject(MemDC, OldBitmap);
- DeleteDC(MemDC);
- ReleaseDC(HWindow, Dc);
- MakeBitmap := HBits
- end;
-
- { DrawBitsApplication }
-
- {- Initialize DrawBitsApplication object's window }
- procedure DrawBitsApplication.InitMainWindow;
- begin
- MainWindow := New(PDrawBitsWindow, Init(nil, 'DrawBits'))
- end;
-
-
- { DrawBitsWindow }
-
- {- Construct DrawBitsWindow object }
- constructor DrawBitsWindow.Init(AParent: PWindowsObject;
- ATitle: PChar);
- begin
- TWindow.Init(AParent, ATitle)
- end;
-
- {- Destroy the DrawBitsWindow object }
- destructor DrawBitsWindow.Done;
- begin
- if TheBitmap <> 0 then
- DeleteObject(TheBitmap);
- TWindow.Done
- end;
-
- {- Create the bitmap and store its handle }
- procedure DrawBitsWindow.SetupWindow;
- begin
- TWindow.SetupWindow;
- TheBitmap := MakeBitmap(HWindow)
- end;
-
- {- Display the bitmap }
- procedure DrawBitsWindow.Paint(PaintDC: HDC;
- var PaintInfo: TPaintStruct);
- var
- MemDC: HDC;
- OldBitmap: HBitmap;
- begin
- MemDC := CreateCompatibleDC(PaintDC);
- OldBitmap := SelectObject(MemDC, TheBitmap);
- BitBlt(PaintDC, 0, 0, bmWidth, bmHeight, MemDC, 0, 0, srcCopy);
- SelectObject(MemDC, OldBitmap);
- DeleteDC(MemDC)
- end;
-
- var
-
- DrawBitsApp: DrawBitsApplication;
-
- begin
- DrawBitsApp.Init('DrawBitsApp');
- DrawBitsApp.Run;
- DrawBitsApp.Done
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 2/15/1991
- ---------------------------------------------------------------}
-